package com.cy.myblog.service.impl;

import com.cy.myblog.dao.ArticleDaoI;
import com.cy.myblog.model.Tarticle;
import com.cy.myblog.service.ArticleServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service("articleService")
public class ArticleServiceImpl implements ArticleServiceI {

	private ArticleDaoI articleDao;
	
	@Autowired
	public void setArticleDao(ArticleDaoI articleDao) {
		this.articleDao = articleDao;
	}

	public Tarticle save(Tarticle article) {
		article.setId(UUID.randomUUID().toString());
		articleDao.save(article);
		return article;
	}

	@Override
	public Tarticle getById(String id) {
		return articleDao.getById(Tarticle.class,id);
	}

	@Override
	public List<Tarticle> findAll() {
		String hql = "from Tarticle order by releasetime desc";
		List<Tarticle> tas =  articleDao.find(hql);
		return tas;
	}

	@Override
	public void update(Tarticle article) {
		articleDao.update(article);
	}

}
